package com.woniuxy.service.impl;

import com.woniuxy.entity.Conllection;
import com.woniuxy.mapper.BlogMapper;
import com.woniuxy.mapper.ConllectionMapper;
import com.woniuxy.service.ConllectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ConllectionServiceImpl implements ConllectionService {
    @Autowired
    private ConllectionMapper conllectionMapper;
    @Autowired
    private BlogMapper blogMapper;

    @Override
    @Transactional
    public void add(Conllection conllection) {
        conllectionMapper.add(conllection);
        blogMapper.plusOne(conllection.getItemId());
    }

    @Override
    @Transactional
    public void cancel(Conllection conllection) {
        conllectionMapper.cancel(conllection);
        blogMapper.subtractOne(conllection.getItemId());
    }

    @Override
    public Integer count(Integer userId) {
        return conllectionMapper.count(userId);
    }

    @Override
    public Conllection check(Integer userId, Integer itemId) {
        return conllectionMapper.check(userId, itemId);
    }

}
